package cn.com.cabinet.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cabinet.service.ILatticeService;
import com.cabinet.service.IMCommoditiesService;
import com.cabinet.web.entity.Commodities;
import com.cabinet.web.entity.Lattice;

import cn.com.cabinet.dto.LatticeDto;

@Service
public class LatticeServiceImpl {
	
	@Autowired
	private ILatticeService iLatticeService;
	
	@Autowired
	private IMCommoditiesService iMCommoditiesService;
	
	
	public List<LatticeDto> getLatticeList(String cid){
		//System.out.println("_________"+cid);
		List<Lattice> la = iLatticeService.getLatticeListByCid(cid);
		List<LatticeDto> laDtoList = new ArrayList<>();
		LatticeDto laDto ;
		
		for (Lattice las : la) {
			laDto = new LatticeDto();
			BeanUtils.copyProperties(las, laDto);
			//System.out.println("--------"+laDto.getId());
			if(las.getCommoditiesId() != null){
				laDto.setCommoditiesName(iMCommoditiesService.getCommoditiesDetail(las.getCommoditiesId()).getCoName());
			}
			
			laDtoList.add(laDto);
		}
		
		return laDtoList;
		
	}
	
	
	public LatticeDto getLatticeOne(Long id){
		
		Lattice la = iLatticeService.getLattice(id);
		LatticeDto laDto = new LatticeDto();
		BeanUtils.copyProperties(la, laDto);
		if(la.getCommoditiesId() != null){
			Commodities co = iMCommoditiesService.getCommoditiesDetail(la.getCommoditiesId());
			laDto.setCommoditiesName(co.getCoName());
			laDto.setCommoditiesphoto(co.getCoPhoto());
		}
		return laDto;
	}
	
	public Lattice getLatticeById(Long id){
		return iLatticeService.getLattice(id);
	}
	
	public void updateLattice(Lattice lattice){
		iLatticeService.updateLattice(lattice);
	}

}
